<%@ page language="java" isELIgnored="false"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
	<script src="/admin/public/html5shiv.min.js"></script>
	<script src="/admin/public/respond.min.js"></script>
<![endif]-->
<title>课程</title>
<!-- Bootstrap core CSS -->
<link href="/admin/public/bootstrap.min.css" title="" rel="stylesheet" />
<link href="/admin/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" />
<link href="/admin/public/animate.css" rel="stylesheet" />
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/pop-up.css" />
<link rel="stylesheet" href="/admin/css/plugins/toastr/toastr.min.css" />
<link rel="stylesheet" type="text/css"
	href="${request.getContext }/admin/css/xcConfirm.css" />
<script src="/admin/My97/WdatePicker.js"></script>
<!-- 时间控件样式 -->
<link
	href="/admin/css/plugins/datetimepicker/bootstrap-datetimepicker.min.css"
	rel="stylesheet" media="screen">
<link href="/admin/public/animate.css" rel="stylesheet">
<link rel="stylesheet" href="/admin/public/inspinia.css" />
<link rel="stylesheet" href="/admin/css/templet_form.css" />
<style>
.form-control{
	margin-left: 0px;
}
.switch{
	visibility:hidden;
}
.today{
	visibility:hidden;
}
</style>
</head>
<body>
	<div id="wrapper" class="container">
		<div class="wrapper wrapper-content">
			<div class="right_box">
				<div style="border: none; box-shadow: none;" class="right_one row">
					<div class="col-md-12 col-sm-12 col-xs-12" style="float: left;">
						<form class="form-horizontal" method="post" id="savecourses"
							novalidate="novalidate">
							<input value="${coursesId }" name="coursesId" type="hidden" />
							<input value="${coursesInfoId }" id="coursesInfoId" type="hidden" />
							<input value="${panduan }" id="panduan" type="hidden" />
							<input value="${minTime }" id="minTime" type="hidden" />
							<input value="${xlystartTime }" id="xlystartTime" type="hidden" />
							<input value="${xlyendTime }" id="xlyendTime" type="hidden" />
							<div class="form-group">
								<a onclick="selPeople('${coursesId }');"  class="up btn btn-primary btn-xs" >查看已预约会员信息</a>
								<a onclick="del('${coursesId }');"  class="btn btn-warning btn-xs" ><i class="fa fa-times" ></i>删除课程</a>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">门店名称:</label>
								<div class="col-lg-6">
									<select id="shopId" name="shopId" class="select2_demo_1 form-control" >
										<c:forEach items="${shopList }" var="sl">
											<option value="${sl.shopId}" <c:if test="${sl.shopId eq shopId }">selected="selected"</c:if>>${sl.shopName}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">教练：</label>
								<div class="col-lg-6">
									<select id="userId" name="userId" class="select2_demo_1 form-control">
										<c:forEach items="${coachList }" var="cl">
											<option value="${cl.userId}" <c:if test="${cl.userId eq userId }">selected="selected"</c:if>>${cl.realname}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">课程：</label>
								<div class="col-lg-6">
									<select id="coursesInfoId" name="coursesInfoId" class="select2_demo_1 form-control">
										<c:forEach items="${subList }" var="bl">
											<option value="${bl.coursesInfoId}" <c:if test="${bl.coursesInfoId eq coursesInfoId }">selected="selected"</c:if>>${bl.coursesName}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-lg-2 control-label">课程日期:</label>
								<div class="col-lg-6">
									<div class="date input-append form_date ymd_date1"
										id="addtimeCalendar" style="float: left; margin-right: 5px;">
										<div class="input-group">
											<input class="form-control input-sm" type="text"
												name="dayTime" id="dayTime" value="${dayTime }"> <span
												class="add-on input-group-addon"
												style="position: relative; left: -40px;"> <i
												class="fa fa-calendar" style="color: black;"></i>
											</span>
										</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-lg-2 col-md-2 col-sm-2 control-label">开始时间：</label>
								<div class="date input-append form_date ymd_date" style="float:left;margin-left:35px;width: 200px;">
									<div class="input-group">
										<input class="form-control input-sm" type="text" name="startTime" id="startTime" 
										value="${startTime }">
										<span class="add-on input-group-addon">
			                            	<i class="fa fa-calendar" style="color:black;"></i>
			                            </span>
									</div>
								</div>
								<span style="float: left;margin-top: 8px;margin-left: 30px;">——</span>
								<div class="date input-append form_date ymd_date"  style="float:left;margin-left:40px;width: 200px;">
									<div class="input-group">
										<input class="form-control input-sm" type="text" name="endTime" id="endTime" 
										value="${endTime }">
										<span class="add-on input-group-addon"><i class="fa fa-calendar" style="color:black;"></i></span>
									</div>
								</div>
							</div>
							<input type="hidden" id="weeks" name="weeks" >
							<input type="hidden" id="checkTF" value="0">
							<input type="hidden" value="${overTime }" name="overTime" id="overTime"/>
							<input type="button" onclick="update();" id="tijiao" style="display: none"/>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="/admin/public/jquery-1.11.3.js"></script>
	<script src="/admin/public/bootstrap.min.js" type="text/javascript"></script>
	<script src="${request.getContext }/admin/js/xcConfirm.js"
		type="text/javascript" charset="utf-8"></script>
	<script src="/admin/js/plugins/toastr/toastr.min.js"></script>
	<script src="/admin/js/new_page.js"></script>
	<!-- 时间控件样式 -->
	<script
		src="/admin/js/plugins/datetimepicker/bootstrap-datetimepicker.min.js"></script>
	<script
		src="/admin/js/plugins/datetimepicker/bootstrap-datetimepicker-update.min.js"></script>
	<script
		src="/admin/js/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
	
	<script>
	$(function(){
		$('.ymd_date1').datetimepicker({　
			minView: "month",
			format: "yyyy-mm-dd",
			language: 'zh-CN',
			autoclose: true,
			pickerPosition: "bottom-left",
			
		});
		$(".ymd_date").datetimepicker({　
			startView:1,
			format: "hh:ii",
			language: 'zh-CN',
			pickerPosition: "bottom-left",
			autoclose: false,
			todayBtn:true,
			minuteStep:5
		});
	})
	function check() {
		var shopId = $("#shopId").val();
		var userId = $("#userId").val();
		var coursesInfoId = $("#coursesInfoId").val();
		var dayTime = $("#dayTime").val();
		var startTime = $("#startTime").val();
		var endTime = $("#endTime").val();
		if (shopId==null || shopId=='') {
			alertNew('请选择门店名称！', false);
			return false;
		}
		if (userId==null || userId=='') {
			alertNew('请选择教练！', false);
			return false;
		}
		if (coursesInfoId==null || coursesInfoId=='') {
			alertNew('请选择课程！', false);
			return false;
		}
		if (dayTime==null || dayTime=='') {
			alertNew('请选择课程日期！', false);
			return false;
		}
		if (startTime==null || startTime=='') {
			alertNew('请选择开始时间！', false);
			return false;
		}
		if (endTime==null || endTime=='') {
			alertNew('请选择结束时间！', false);
			return false;
		}
		return true;
	}
		
	//修改
	function update() {
		if (check()) {
			//判断星期几
			var dayTime = $("#dayTime").val();
			var day = new Date(Date.parse(dayTime));   //需要正则转换的则 此处为 ： var day = new Date(Date.parse(date.replace(/-/g, '/')));  
			 var today = new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六');  
			 var week = today[day.getDay()]; 
			 $("#weeks").val(week);
			var panduan = $("#panduan").val();
			var overTime = $("#overTime").val();
			 if(overTime == 1){
				$.ajax({
					type : "post",
					data : $("#savecourses").serialize(),
					dataType : "json",
					url : "/courses/updateCoursesById",
					success : function(data) {
						$("#checkTF").val("1");
						if (data.success) {
							alertNew(data.msg, true);
						}
					},
					error : function(data) {
						alert("修改失败！");
					}
				});
			}else{
				alert("课程时间已过，不可修改！")
			} 
				
		}
	}
	
	//删除信息
	function del(coursesId){
		var minTime = $("#minTime").val();
		var xlystartTime = $("#xlystartTime").val();
		var xlyendTime = $("#xlyendTime").val();
		var panduan = $("#panduan").val();
		var coursesInfoId = $("#coursesInfoId").val();
		window.wxc.xcConfirm("确定要删除吗？", window.wxc.xcConfirm.typeEnum.confirm,{onOk:function(){ 
  			$.post("/courses/deleteCoursesById",{"coursesId":coursesId},
  			function(data){
  				window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.info,
						{onOk:function(){
							if(panduan==0){
								//团课私教
								$('#ifr', window.parent.document).attr('src',
								'/courses/scheduling');
							}
							if(panduan==1){
								//训练营
								$('#ifr', window.parent.document).attr('src',
										'/courses/xlypk?coursesInfoId='+coursesInfoId+'&panduan='+1+'&minTime='+minTime+'&xlystartTime='+xlystartTime+'&xlyendTime='+xlyendTime);
							}
						}}
				)
  			});
  		}})
	}
	
	//查看课程下的会员信息
	function selPeople(coursesId){
		var panduan = $("#panduan").val();
		var minTime = $("#minTime").val();
		var xlystartTime = $("#xlystartTime").val();
		var xlyendTime = $("#xlyendTime").val();
		window.location.href="/courses/selectUserByCoursesId?coursesId="+coursesId+'&panduan='+panduan+"&minTime="+minTime+"&xlystartTime="+xlystartTime+"&xlyendTime="+xlyendTime;
	}
	
	</script>
</body>
</html>